/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.unju.fi.reservahabitaciones.grupo14.struts.forms;

import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dao.UsuarioDao;
import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dao.impl.UsuarioDaoImpl;
import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dominio.Usuario;
import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.spring.servicios.ServicioFacade;
import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.spring.servicios.SpringUtil;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author mauriljb
 */
public class LoginActionForm extends org.apache.struts.action.ActionForm {
    ServicioFacade servicio = (ServicioFacade) SpringUtil.getBean("servicioFacade");
    String usuarioId;
    String pass;

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getUsuarioId() {
        return usuarioId;
    }

    public void setUsuarioId(String usuarioId) {
        this.usuarioId = usuarioId;
    }

    /**
     *
     */
    public LoginActionForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
 UsuarioDao ud = servicio.getUsuarioDao();
            Usuario us = ud.getUsuarioByLogin(usuarioId, pass);
            if(us == null){
            errors.add("accessError", new ActionMessage("error.userId.noexist"));
        }
            return errors;
        }
}
